package org.bugjail.servlet.form.edit;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.bugjail.data.Suite;
import org.bugjail.dataaccess.DAOFactory;
import org.bugjail.servlet.BasicUIServlet;

/**
 * Servlet implementation class for Servlet: NewSuiteFormServlet
 * 
 */
public class EditSuiteFormServlet extends BasicUIServlet {

	static final long serialVersionUID = 1L;

	private Suite suite;
	
	@Override
	protected void write(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		//int testdesignid = Integer.parseInt(request
		//		.getParameter("testdesignid"));

		PrintWriter pw = response.getWriter();

		pw.println("<form method='post' action='EditSuiteServlet'>");
		pw
				.println("Suite name:<br><input type='text' name='name' maxlength='50' value='"+suite.getName()+"' /><br>");
		pw
				.println("Suite description:<br><textarea name='description'>"+suite.getDescription()+"</textarea><br>");
		pw.println("<input type=hidden name='suiteid' value='" + suite.getId() + "' />");
		pw.println("<input type=submit value='Update' />");
		pw.println("&nbsp;<a href='SuiteServlet?testdesignid="+suite.getTestDesign().getId()+"'>Cancel</a>");
		pw.println("</form>");
	}

	@Override
	protected String pageTitle() {
		return "Edit suite";
	}

	@Override
	protected void beforeAction(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		int suiteid = Integer.parseInt(request.getParameter("suiteid"));
		suite = DAOFactory.getDAOFactory().getSuiteDAO().retrieveById(suiteid);
	}
}